﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Common;
using AspNetCs.Enumerations.Channel_Enum;
using AspNetCs.Enumerations;
using AspNetCs.Bll;

public partial class Master_Admin_TempleList : Admin_BasePage
{
    protected int TempleTypeId = 0;
    protected string TempleTypeName = "";
    protected string WhereStr = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        IsExit();

        if (Request["channelId"] != null)
        {
            TempleTypeId = StringHelper.isNumber_int(Request["channelId"].ToString());
        }
        if (!Enum.IsDefined(typeof(Channel_Type), TempleTypeId))
        {
            ShowMsgBack("频道参数错误!");
            Response.End();
        }
        switch ((Channel_Type)TempleTypeId)
        {
            case Channel_Type.cemetery:
                TempleTypeName = EnumDescription.GetFieldText(Channel_Type.cemetery);


                break;
            case Channel_Type.clan:
                TempleTypeName = EnumDescription.GetFieldText(Channel_Type.clan);
                break;

            case Channel_Type.gravestone:
                TempleTypeName = EnumDescription.GetFieldText(Channel_Type.gravestone);
                break;
            case Channel_Type.memorial:
                TempleTypeName = EnumDescription.GetFieldText(Channel_Type.memorial);
                break;
        }
        WhereStr = " ChannelID=" + TempleTypeId;
        if (!Page.IsPostBack)
        {
            Bind();
        }
    }

    protected void Bind()
    {
        this.AspNetPager1.UrlRewritePattern = "memorial_List_{0}.Aspx";
        this.AspNetPager1.PageSize = 15;
        Pager p = new Pager();
        p.PageIndex = this.AspNetPager1.CurrentPageIndex;
        p.Ident = "id";
        p.Obj = Repeater1;
        p.Orderfld = "Addtime";
        p.OrderType = "desc";
        p.PageIndex = this.AspNetPager1.CurrentPageIndex;
        p.PageSize = this.AspNetPager1.PageSize;
        p.TableName = "TempleList";
        p.WhereStr = WhereStr;
        p.ControlBind();
        this.AspNetPager1.RecordCount = p.recordcount();
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        Bind();
    }
    protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "delinfo")
        {
            string id = e.CommandArgument.ToString();
            if (TempleBll.CreateNew.delete(" id=" + id.ToString()) > 0)
            {
                ResultStr("Admin_TempleList.aspx?channelId=" + TempleTypeId, "删除成功！");
                Response.End();
            }
            else
            {
                ShowMsgBack("删除失败!");
                Response.End();
            }


        }
    }

    protected string ChannelTypesBind(Object obj)
    {
        string Result = "";
        switch ((Channel_Type)TempleTypeId)
        {
            case Channel_Type.cemetery:
                TempleTypeName = EnumDescription.GetFieldText(Channel_Type.cemetery);
                Result = "--";
                break;
            case Channel_Type.clan:
                TempleTypeName = EnumDescription.GetFieldText(Channel_Type.clan);
                Result = "--";
                break;

            case Channel_Type.gravestone:
                TempleTypeName = EnumDescription.GetFieldText(Channel_Type.gravestone);
                Result = Enum.GetName(typeof(NetMuTypeEnum), obj);

                break;
            case Channel_Type.FindFamily:
                TempleTypeName = EnumDescription.GetFieldText(Channel_Type.FindFamily);
                Result = "--";
                break;
            case Channel_Type.memorial:
                TempleTypeName = EnumDescription.GetFieldText(Channel_Type.memorial);
                Result = Memorial_TypeBll.CreateNew.GetModel(StringHelper.isNumber_int(obj.ToString())).TypeName;
                break;
        }

        return Result;
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Footer)
        {
            Panel pl = e.Item.FindControl("pl_nothing") as Panel;
            if (Repeater1.Items.Count <= 0)
            {
                pl.Visible = true;
            }
        }
    }
}
